import usart from '@ohos.Multimedia.usart';

//维护JS端缓存
class UsartYielder{
	constructor(int_port){
		this.int_port = int_port;
		this.queue=[];
	}
	getbyte(int_bytes=1){
		var res = new Array(int_bytes);
		const ttyAMA0=0;
		while(int_bytes>0){
			while(this.queue.length ==0){
				const U8Array =  usart.readFromLoopingQueue(ttyAMA0);
				const arr =U8Array.toArray();
				this.queue=this.queue.concat(arr);
			}
			res.push(this.queue.shift());
			--int_bytes
		}
		return res;
	}
}